#region Imports

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using MetaSapiens.PageMethods;

#endregion Imports

/// <summary>
/// Demonstrates the use of array or custom types as parameters.
/// </summary>
public partial class Serialization : MetaSapiens.PageMethods.BasePageWithoutDefaultMethod
{
  protected void Page_Load(object sender, EventArgs e)
  {
  }

  private String ArrayToString(Array array)
  {
    StringBuilder stringBuilder;

    stringBuilder = new StringBuilder();
    stringBuilder.Append('[');
    for (int i = 0; i < array.Length; i++)
    {
      if (i > 0)
        stringBuilder.Append(',');
      stringBuilder.Append(array.GetValue(i));
    }
    stringBuilder.Append(']');

    return stringBuilder.ToString();
  }

  [PageMethod]
  public void DisplayArray([ParamRequired] String[] value)
  {
    LiteralArray.Text = ArrayToString(value);

    FieldSetArray.Visible = true;
  }

  [PageMethod]
  public void DisplayCustomObject([ParamRequired] CustomObject value)
  {
    LiteralInteger.Text = value.AnInteger.ToString();
    LiteralString.Text = value.AString;
    LiteralDateTime.Text = value.ADateTime.ToString();
    LiteralDecimal.Text = value.ADecimal.ToString();
    LiteralCustomObjectArray.Text = ArrayToString(value.AnArray);
    LiteralStruct.Text = value.AStruct.ToString();
    LiteralSubObject.Text = value.ASubObject.ToString();

    FieldSetCustomObject.Visible = true;
  }

  [PageMethod]
  public void DisplayCustomObjectWithTypeConverter([ParamRequired] CustomObject3 value)
  {
    LiteralX.Text = value.X.ToString();
    LiteralY.Text = value.Y.ToString();

    FieldSetTypeConverter.Visible = true;
  }
}
